
$(function(){
    $("#fo").validate({
        rules:{
            name: {
                required: true
            },
            password: {
                required: true
            },
            code: {
                required: true,
                remote: {
                    url: "../../home.html?c=session&m=_session",
                    type: "post",
                    dataType: "json"
                }
            }
        },
        messages:{
            name:{
                required:"请输入用户名！"
            },
            password:{
                required:"请输入密码！"
            },
            code:{
                required:"请输入验证码！",
                remote:"验证码不符！"
            }
        }
    });

    $("#_img").click(function(){
        this.src ="../../Public/php/img.php?"+Math.random();
    });
});
$.validator.setDefaults({
    submitHandler:function(form){
        var username = $("#loginuser");
        var password = $("#loginpwd");
            $.ajax({
                type: "post",
                url: "../../home.html?c=ht_login&m=htdl_login",
                dataType: "json",
                data: {
                    username: username.val(),
                    password: password.val()
                },
                success: function (msg) {
                    if (msg) {
                        layer.open({
                            content: '恭喜你登录成功',
                            btn: ['跳转到管理页面', '留在本页'],
                            yes: function () {
                                window.location.href = 'ht_index.html';
                            }
                        })
                    }
                },
                error: function () {
                    alert("123");
                    return false;
                }
            })


    }
});

